<template>
    <div class="comment-reply">

        <!-- 头部信息 -->
        <van-nav-bar :title="`${comment.reply_count}条回复`">
            <van-icon 
                slot="left"
                @click="$emit('close')"
                name="cross" 
            />
        </van-nav-bar>
         <!-- 头部信息 -->

          
        <!-- 当前评论项 -->
        <comment-item 
            :comment="comment"
        />
        <!-- /当前评论项 -->

        <!-- 所有评论回复 -->
        <comment-list 
            :source="comment.com_id"
            type="c"
            :list="commentList"
        />
        <!-- /所有评论回复 -->

        <!-- 底部区域 -->
        <div class="article-bottom">
            <van-button
                class="comment-btn"
                type="default"
                round
                @click="show=true"
                size="small"
            >写评论</van-button>
            
        </div>
        <!-- /底部区域 -->

        <!-- 评论回复 -->
        <van-popup 
            v-model="isShow" 
            position="bottom"  
        >
            <post-comment 
                :target="comment.com_id"
                :articleId="articleId"
                @post-success="onPostSuccess"
            />
        </van-popup>
        <!-- /评论回复 -->
    </div>
</template>
<script>
import commentItem from './comment-item.vue'
import commentList from './comment-list.vue'
import PostComment from './post-comment.vue'
export default {
    components: { 
        commentItem,
        commentList,
        PostComment
    },
    props:{
        comment:{
            type:Object,
            required:true
        },
        articleId:{
            type:[Number,String,Object],
            required:true
        }
    },
    data() {
        return {
            isShow:false,
            commentList:[]
        }
    },
    methods: {
        onPostSuccess(comment){

            this.commentList.unshift(comment)
            this.comment.reply_count++
            this.isShow = false
        }
    }
    
}
</script>
<style lang="less" scoped>
.van-icon{
    color: turquoise;
}
.article-bottom {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    justify-content: space-around;
    align-items: center;
    box-sizing: border-box;
    height: 44px;
    border-top: 1px solid #d8d8d8;
    background-color: #fff;
    .comment-btn {
      width: 141px;
      height: 23px;
      border: 1px solid #eeeeee;
      font-size: 15px;
      line-height: 23px;
      color: #a7a7a7;
    }
    .van-icon {
      font-size: 20px;
      .van-info {
        font-size: 11px;
        background-color: #e22829;
      }
    }
  }
</style>